import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class Test extends Component {
  static propTypes = {
    colors: PropTypes.array,
  }
  /* static defaultProps = {
    colors: ['red', 'green', 'blue'],
  } */
  render() {
    // !建议：ES6
    const { colors = ['red', 'green', 'blue'] } = this.props
    return (
      <div>
        <ul>
          {colors.map((item) => (
            <li key={item} style={{ backgroundColor: item }}>
              {item}
            </li>
          ))}
        </ul>
      </div>
    )
  }
}

// 静态属性
/* Test.defaultProps = {
  colors: ['red', 'green', 'blue'],
} */
